#include "Awesome.h"
#include <iostream>

extern int N;
Awesome::Awesome(vector<OSThread*>* threads, int quanta) :
	OSScheduler(*threads), quanta(quanta), P(N, quanta), lastThread(0)
{
}

Awesome::~Awesome()
{
}

void Awesome::increasePriority(int t){
	P[t]++;
}

void Awesome::runSomeThread(){
	int t=(lastThread == (N-1)) ? 1 : (lastThread + 1);
	for(int i=1; i<N; i++)
		if (P[i] > P[t])
			t=i;
	//now t is the id of the thread with the highest priority

	//cout << "thread "<<t<<" has priority "<<P[t]<<endl;
	giveQuanta(t, P[t]+1);
	P[t] = 0;
	//cout << "thread "<<t<<" used "<<P[t]<<" of his quanta"<<endl;
	lastThread=t;
	return;
}
